home *** CD-ROM | disk | FTP | other *** search
- /* open.c --- p 501 */
- #include <stdio.h>
- #include <io.h>
- #include <fcntl.h>
- #include <sys\types.h>
- #include <sys\stat.h>
- main()
- {
- int handle;
- char filename[81];
- printf("Enter name of a file to open: ");
- gets(filename);
- /* Open the file for write operations.
- * Don't overwrite existing file. */
- if ((handle = open(filename, O_WRONLY | O_CREAT | O_EXCL,
- S_IREAD | S_IWRITE)) == -1)
- /* Use perror to print the message so that we also see
- * the error message corresponding to the value of 'errno'*/
- perror("Open failed! ");
- else
- printf("File %s opened successfully\n",filename);
- /* In an actual program we will use the file for I/O.
- * Here we simply exit. */
- }